import java.util.Arrays;

public class BinarySortTest {
    /**
     * 对常见的二分查找的边界值和游标条件进行测试
     */
    public static void main(String[] args) {
        int []a=new int[]{1,3,2,0,8,5,19,7,22,6,12,15,47,9,45,4};
        binary(a);
        System.out.println(Arrays.toString(a));
    }
    public static void binary(int []a){
        int n=a.length;
        for(int i=1;i<n;i++) {
            int left = 0;
            int right = i - 1;
            int x = a[i];
            int j=i-1;

            while (left <= right) {
                int middle = left + (right - left) / 2;
                if (x > a[middle]) {
                    left = middle + 1;
                } else {
                    right = middle - 1;
                }
            }
            while(j>=left){
                a[j+1]=a[j];
                j--;
            }
            a[left]=x;
        }
    }
}
